We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Why use model->create() method will do select twice when assign primary key culumn

CREATE TABLE test ( id int(11) unsigned NOT NULL AUTO_INCREMENT, age int(11) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

$t = new Test(); $t->id = 1; $t->create();

then log writes SELECT IF(COUNT(*)>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='test' DESCRIBE test SELECT COUNT() "rowcount" FROM test WHERE id = ? SELECT COUNT() "rowcount" FROM test WHERE id = ? INSERT INTO test (age, id) VALUES (?, ?)

if i use save() instend of create(), it's only once select

ORM needs to know the table structure, see models meta data